﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebeTerm.Common;
using System.Web.Script.Serialization;

namespace WebeTerm.Web
{
    public class WebIMAsyncHandler : IHttpAsyncHandler
    {
        #region IHttpAsyncHandler 成员

        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            string _UID = context.Request.Params["uid"];

            WebIMClientAsyncResult _AsyncResult = new WebIMClientAsyncResult(context, cb, extraData);

            string _Content = context.Request.Params["content"];
            string _Action = context.Request.Params["action"];

            if (_Action == "login")
            {
                _UID = context.Request.Params["uid"];
                _AsyncResult.LoginID = _UID;
                //WebIMMessageHandler.Instance().Login(_UID, _AsyncResult);
            }
            else if (_Action == "logout")
            {
                _AsyncResult.LoginID = _UID;
                //WebIMMessageHandler.Instance().Logout(_UID, _AsyncResult);
            }
            else if (_Action == "connect")
            {
                _AsyncResult.LoginID = _UID;
                //WebIMMessageHandler.Instance().Connect(_AsyncResult);
            }
            else if (_Action == "getuserlist")
            {
                _AsyncResult.LoginID = _UID;
                //WebIMMessageHandler.Instance().GetUserList(_AsyncResult);
            }
            //增加消息发送
            else if (_Action == "sendmsg")
            {

                _AsyncResult.LoginID = _UID;

                //调用
                //WebIMMessageHandler.Instance().AddMessage(_Content, _AsyncResult);

            }

            //调用
            //WebIMMessageHandler.Instance().AddMessage(_Content, _AsyncResult);
            return _AsyncResult;
        }

        public void EndProcessRequest(IAsyncResult result)
        {

        }

        #endregion

        #region IHttpHandler 成员

        public bool IsReusable
        {
            get { return false; ; }
        }

        public void ProcessRequest(HttpContext context)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}